<?php

class Zend_View_Helper_FormCkeditor extends Zend_View_Helper_FormTextarea
{

    /**
     * Generate html for element ckeditor
     * @return string
     */
    public function formCkeditor($name, $value = null, $attribs = null, $options = null)
    {
        $html = parent::formTextarea($name, $value, $attribs);
        $html .= $this->_generalJsCkeditor($name, $attribs); //die;
        return $html;
    }

    /**
     * General js for ckediotor
     * @param string $name
     * @param array $attribs
     * @return string
     */
    private function _generalJsCkeditor($name, $attribs)
    {
        /* $script = '<script type="text/javascript">
          CKEDITOR.replace( "' . $name . '" , {
          filebrowserBrowseUrl : "'.$attribs['config']['directory_upload'].'",
          filebrowserUploadUrl : "'.$attribs['config']['directory_upload'].'",
          toolbar: "' . $attribs['config']['toolbar'] . '",'.$this->_getWidth($attribs).$this->_getHeight($attribs).'
          enterMode : CKEDITOR.ENTER_BR,
          shiftEnterMode: CKEDITOR.ENTER_BR
          });
          </script>'; */

        $script = '<script type="text/javascript">
                            CKEDITOR.replace("' . $name . '");
                        </script>';
        return $script;
    }

    /**
     * Get width of ckeditor from config attribute
     * @param array $attribs
     * @return string
     */
    private function _getWidth($attribs)
    {
        if (isset($attribs['config']['width'])) {
            return 'width:"' . $attribs['config']['width'] . '",';
        }
        return '';
    }

    /**
     * Get height of ckeditor from config attribute
     * @param array $attribs
     * @return string
     */
    private function _getHeight($attribs)
    {
        if (isset($attribs['config']['height'])) {
            return 'height:"' . $attribs['config']['height'] . '",';
        }
        return '';
    }

}